import { network } from "../../utils/network.js";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    type:1,
    items:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    wx.showLoading({
      title: '加载中...',
    })

    var that=this
    that.setData({
      value:options.value
    })

    network.getSearch({
      w: options.value,
      success: function (songs) {
        console.log(songs)
        that.setData({
          songs: songs
        })
      }
    }),

    network.getDetail_search({
      w: options.value,
      success: function (data) {
        that.setData({
          items: that.data.songs,
          songs: that.data.songs,
          artists: data.artists,
          albums: data.albums,
          playlists: data.playlists
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () { 
    wx.hideLoading()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  back:function(){
    wx.navigateBack()
  },
  onsongs:function(){
      this.setData({
      items: this.data.songs,
      type: 1
    })
  },
  onartists: function () {
    this.setData({
      items: this.data.artists,
      type: 2
    })
  },
  onalbums: function () {
    this.setData({
      items: this.data.albums,
      type: 3
    })
  },
  onplaylists: function () {
    this.setData({
      items: this.data.playlists,
      type: 4
    })
  }
})